package com.yanqu.road.server.cmd.activity.chuhan.cross;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.ChuHanProto;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.command.Command;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.manger.player.GamePlayerMgr;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameProtocol;
import com.yanqu.road.server.protocol.Protocol;
import io.netty.channel.ChannelHandlerContext;


@Cmd(code = GameProtocol.S_CROSS_CHUHAN_NPC_EVENT_SYNC, desc = "")
public class ChuHanNpcEventSyncCmd implements Command {

    @Override
    public void execute(ChannelHandlerContext ctx, YanQuMessage packet) throws Exception {
        ChuHanProto.CrossChuHanEventSyncMsg syncMsg = ChuHanProto.CrossChuHanEventSyncMsg.parseFrom(packet.getBytes());
        for(ChuHanProto.CrossChuHanEventTempMsg userEventMsg : syncMsg.getEventsList()){
            long userId = userEventMsg.getUserId();
            GamePlayer player = GamePlayerMgr.getOnlinePlayer(userId);
            if(player != null){
                ChuHanProto.ChuHanSyncEventRespMsg.Builder syncUserMsg = ChuHanProto.ChuHanSyncEventRespMsg.newBuilder();
                for(ChuHanProto.ChuHanEventMsg eventMsg : userEventMsg.getEventsList()){
                    syncUserMsg.addEvents(eventMsg);
                }
                player.sendPacket(Protocol.S_CHUHAN_SYNC_EVENT % 20000, syncUserMsg);
            }
        }
    }
}
